/**
  * 
  * Videotify is a program used to convert video to flv and upload it to a server
  * 
  * Copyright (C) 2011 André Mörke
  *							  
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * 
  */

package de.osflex.videotify.ui.models
{
	import de.osflex.videotify.events.MainUIEvent;
	
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.filesystem.File;
	
	public class MainUIPresenter extends EventDispatcher
	{
		private var _dispatcher : IEventDispatcher;
		[Bindable]public var currentConvertMode : String = 'fast';
		[Bindable]public var strOutput : String = '';		
		/**
		 * Selected file from the file dialoge
		 */
		[Bindable]public var file : File;
		
		/**
		 * The converted video
		 */
		[Bindable]public var pathToVideo : String = '';
		
		
		/**
		 * Current state of the main ui
		 */
		[Bindable]public var stateStatus : String = 'home';
		
		
		/**
		 * Constuctor get the core EventDispatcher from the EventMap
		 * 
		 * @param _coreEventDispatcher IEventDispatcher
		 */
		
		public function MainUIPresenter(_coreDispatcher:IEventDispatcher=null)
		{
			this._dispatcher = _coreDispatcher;
		}		
		
		/**
		 * If a property for converting the video was changed in the ui
		 * this will fire an according event
		 * 
		 * @param _data Object
		 * @return void
		 */
		
		public function changeConvertProperty(_data : Object) : void
		{
			var convertPropertyChangedEvent : MainUIEvent = new MainUIEvent(MainUIEvent.CONVERT_PROPERTY_CHANGE);
			convertPropertyChangedEvent.data = _data;
			this._dispatcher.dispatchEvent(convertPropertyChangedEvent);
		}
		
		/**
		 * Opens the file dialog to select the file wich should be converted to flv
		 * 
		 * @return void
		 */
			
		public function openFileDialog() : void
		{
			var openFileDialogEvent : MainUIEvent = new MainUIEvent(MainUIEvent.OPEN_FILE_DIALOG);
			this._dispatcher.dispatchEvent(openFileDialogEvent);
		}
		
		/**
		 * Starts converting the video and uploading it to the server
		 * 
		 * @return void
		 */
		
		public function	convertAndUploadFile() : void
		{
			var evt : MainUIEvent = new MainUIEvent(MainUIEvent.CONVERT_AND_UPLOAD_FILE)				
			evt.data = {file:this.file,
						mode:this.currentConvertMode};	
			this._dispatcher.dispatchEvent(evt);			
		}
		
		/**
		 * Cancels the convert process
		 * 
		 */
		
		public function cancelConvert() : void
		{
			this._dispatcher.dispatchEvent(new MainUIEvent(MainUIEvent.CANCEL_CONVERT_PROCESS));
		}
		
		

	}
}